package T03_ThreadState;

import java.util.concurrent.TimeUnit;

public class S004 {
  public static void main(String[] args) throws InterruptedException {
    Object o = new Object();
    
    Thread t1 = new Thread(() -> {
      synchronized (o) {
        while (true) {
        }
      }
    });
    
    Thread t2 = new Thread(() -> {
      synchronized (o) {
        System.out.println("也开始抢锁");
      }
    });
    
    // 启动后 抢锁
    t1.start();
    TimeUnit.SECONDS.sleep(1);
    // 也开始 尝试抢锁
    t2.start();
    TimeUnit.SECONDS.sleep(1);
    // 因为线程t1 已经抢到锁了，所以当t2开始抢锁的时候 直接阻塞了
    System.out.println(t2.getState());
  }
}
